#include <iostream>
#include <stack>
using namespace std;

int main()
{
    int N = 0;
    cin >> N;

    int first = 0, second = 1, sum = 0;
    while (sum < N)
    {
        sum = first + second;
        first = second;
        second = sum;
    }

    int ans = min(N - first, second - N);
    cout << ans << endl;
    return 0;
}


class Parenthesis {
public:
    bool chkParenthesis(string str, int n)
    {
        stack<char> st;

        for (int i = 0; i < n; i++)
        {
            if ((str[i] == '{')
                || (str[i] == '[')
                || (str[i] == '('))
            {
                st.push(str[i]);
            }
            else if ((str[i] == ']')
                || (str[i] == ')')
                || (str[i] == '}'))
            {
                if (!st.empty())
                {
                    char tmp = st.top();
                    st.pop();
                    if ((((str[i] == ']') && (tmp == '['))
                        + ((str[i] == '}') && (tmp == '{'))
                        + ((str[i] == ')') && (tmp == '('))) == 0)
                    {
                        return  false;
                    }
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }

        return st.empty();
    }
};